package com.example.helloworld;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.example.helloworld.util.LifecycleLog;

public class LifecycleAncestor extends Activity {

	private String activityName;
	private TextView textStatus;
	private TextView textMethod;

		private void logging(final String log) {
			LifecycleLog.addLog(activityName, log);
			LifecycleLog.printStatus(textMethod, textStatus);
		}
	
		private void callActivity(final Class<?> cls) {
			Intent intent =	new Intent(this, cls);
			startActivity(intent);
		}
		
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_lifecycle_ancestor);
		
		activityName =	getString(R.string.ancestor);
		textStatus =	(TextView)findViewById(R.id.textStatus);
		textMethod =	(TextView)findViewById(R.id.textMethod);
		
		logging(getString(R.string.on_create));
	}

	@Override
	protected void onStart() {
		super.onStart();
		logging(getString(R.string.on_start));
	}
	
	@Override
	protected void onRestart() {
		super.onRestart();
		logging(getString(R.string.on_restart));
	}

	@Override
	protected void onResume() {
		super.onResume();
		logging(getString(R.string.on_resume));
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		logging(getString(R.string.on_pause));
	}

	@Override
	protected void onStop() {
		super.onStop();
		logging(getString(R.string.on_stop));
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		logging(getString(R.string.on_destroy));
	}
	
	public void startParent(View view) {
		callActivity(LifecycleParent.class);
	}
	
	public void startChild(View view) {
		callActivity(LifecycleChild.class);
	}
	
	public void startDialog(View view) {
		callActivity(LifecycleDialog.class);
	}
	
	public void finishActivity(View view) {
		this.finish();
	}

}
